<?php
//include file
include("../include/session.php");
require_once('../db_conn/conn_db.php');
require_once('header.php');
require_once('../calendar/calendar/classes/tc_calendar.php');
?>
<script language="javascript" src="../calendar/calendar/calendar.js"></script>
<SCRIPT LANGUAGE="JavaScript">
function fjs_formval()
	{
	error = 0;
	if (window.document.form.tema.value == "")
	{
		alert("ATTENTION \n\nField Tema Buku must be filled.");
		window.document.form.tema.focus();
		error = 1;
	}
	
	else
	if (window.document.form.judul.value == "")
	{
		alert("ATTENTION \n\nField Judul Buku must be filled.");
		window.document.form.judul.focus();
		error = 1;
	}
	
	if (error == 0)
		window.document.form.submit();
	else
	return false;
}</SCRIPT>
</HEAD>
<BODY>
<?php 
$action = (!empty($_GET['id'])) ? 'update' : 'save';
$result = get_order($_GET['id']);
$row1 = mysql_fetch_array($result);
?>
<FORM ACTION=save_order.php?action=<?php echo $action?> method="post" name="form" id="form" enctype="multipart/form-data">
<table align="left" cellpadding="1" cellspacing="1" border="1">
	<tr>
		<td class="pageName" colspan="2">Form Order</td>
	</tr>
	<tr> 
      <td>Klien Name</td>
	  <td>
	  <?php 
		$result = get_all_klien();
		
		echo "<select name=klien_id>
		<option value='' selected=\"\">---pilih---</option>"; 
		while ($row = mysql_fetch_array($result)) {?>
			<option value=<?php echo $row[0]?> <?php if($row[0]==$row1['1']) echo "selected";?> ><?php echo $row[2] ?></option>";
		<?php } ?>
		</select>
		
	  </td>
    </tr>
	<tr> 
      <td>Tema Buku</td>
	  <td><input type=text name=tema value="<?php echo $row1['tema_buku']?>" size=40></td>
    </tr>
	<tr> 
      <td>Judul Buku</td>
	  <td><input type=text name=judul value="<?php echo $row1['judul_buku']?>" size=40></td>
    </tr>
	<tr> 
      <td>Jumlah Halaman</td>
	  <td><input type=text name=jumlah value="<?php echo $row1['jml_halaman']?>" size=15></td>
    </tr>	
	<tr> 
      <td>Cover</td>
	  <td><input type=text name=cover value="<?php echo $row1['cover']?>" size=40></td>
    </tr>
	<tr> 
      <td>Jenis Kertas</td>
	  <td><input type=text name=jns_kertas value="<?php echo $row1['jns_kertas']?>" size=40></td>
    </tr>
	<tr> 
      <td>Cost</td>
	  <td><input type=text name=cost value="<?php echo $row1['cost']?>" size=40></td>
    </tr>
	<tr> 
      <td>Payment Status</td>
	  <td>
		<select name="payment">
			<option value="0" <?php if($row1[9]==0) echo "selected";?>>Un Paid</option>
			<option value="1" <?php if($row1[9]==1) echo "selected";?>>50%</option>
			<option value="2" <?php if($row1[9]==2) echo "selected";?>>100%</option>
		</select>	
	  </td>
    </tr>
	<?php if (empty($_GET['id'])) { ?>
	<input type=hidden name=status value="1" size=20>
	<?php } else { ?>
	<input type=hidden name=id value="<?php echo $_GET['id']?>" size=20>
	<tr>
	<td>Status</td>
	<td>
	<select name=status>
		<option value=1 <?php if(1==$row1['status']) echo "selected";?>>Active</option>
		<option value=2 <?php if(2==$row1['status']) echo "selected";?>>Pending</option>
		<option value=12 <?php if(12==$row1['status']) echo "selected";?>>Penulisan</option>
		<option value=99 <?php if(99==$row1['status']) echo "selected";?>>Selesai</option>
	</select>
	</td>
	</tr>
	<?php } ?>
	<tr> 
    <td>Target Finished</td>
	  <td>
		<?php
		  $myCalendar = new tc_calendar("target", true, false);
		  $myCalendar->setIcon("../calendar/calendar/images/iconCalendar.gif");
		  $myCalendar->setDate(date('d'), date('m'), date('Y'));
		  $myCalendar->setPath("../calendar/calendar/");
		  $myCalendar->setYearInterval(2010, 2015);
		  $myCalendar->dateAllow("2013-01-01", '2015-03-01');
		  $myCalendar->setDateFormat('j F Y');
		  //$myCalendar->setHeight(350);	  
		  //$myCalendar->autoSubmit(true, "form1");
		  $myCalendar->setAlignment('left', 'bottom');
		  $myCalendar->setSpecificDate(array("2013-01-01", "2013-01-01", "2111-12-25"), 0, 'year');
		  $myCalendar->writeScript();
		  ?>
	  </td>
    </tr>
	<tr> 
      <td>Input File</td>
      <td><input type=file name=file id=file size="20"></td>
    </tr>
	 <td><input type=submit value=Simpan onClick="javascript:return fjs_formval()"> <input type=reset value=Reset></td>
    </tr>
</table>
</FORM>
</BODY>
</HTML>
